/**
 * @author Linrui
 * @since 2011-04-29
 * 首页菜单拦截检测
 */
package com.qeado.util.interceptors;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.qeado.sort.model.Sort;
import com.qeado.sort.service.SortService;

@Component
public class IndexMenuInterceptor extends AbstractInterceptor {

	@Autowired
	private SortService sortService;

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		List<Sort> mainSort;
		/*
		 * if the main sort menu are not load into the index page , they will be
		 * load in the indexInterceptor .
		 */
		if ( null == ActionContext.getContext().getSession().get("indexMainMenu")) {
			mainSort = sortService.listTopCategory(); // 查询所有的商品一级类别
			ActionContext.getContext().getSession().put("indexMainMenu",
					mainSort);
		}
		return invocation.invoke();
	}

}
